//
//  Request.h
//  PatientNew
//
//  Created by xxx on 14-7-11.
//  Copyright (c) 2014年 wtf. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "DDXML.h"
#import "Response.h"

@class Config;

@interface Request : NSObject

// request methods
#define kHttpRequestMethodGet    @"GET"
#define kHttpRequestMethodPOST   @"POST"
#define kHttpRequestMethodPUT    @"PUT"
#define kHttpRequestMethodDELETE @"DELETE"

// cookie names
#define kCookieNameSessionId @"sessionId"
#define kCookieNamePvId      @"pvId"

// default time out seconds
typedef NS_ENUM(int, tTimeOutSeconds) {
    kTimeOutSecondsDefault = 5,
    kTimeOutSecondsLong    = 20
};

// xml node names
#define kXMLNodeNameRequestName           @"name"
#define kXMLNodeNameRequestSecured        @"secured"
#define kXMLNodeNameRequestCached         @"cached"
#define kXMLNodeNameRequestSignInRequired @"singInRequired"
#define kXMLNodeNameRequestUrlString      @"url"
#define kXMLNodeNameRequestHttpMethod     @"httpMethod"
#define kXMLNodeNameRequestTimeOutSeconds @"timeOutSeconds"
//#define kXMLNodeNameRequestApiVersion     @"version"

@property (nonatomic, strong) NSString *name;

@property (nonatomic) BOOL secured;
@property (nonatomic) BOOL cached;
@property (nonatomic) BOOL signInRequired;

@property (nonatomic, strong) NSString *urlString;
@property (nonatomic, strong) NSString *httpMethod;
//@property (nonatomic, strong) NSString *apiVersion;

@property (nonatomic, strong) NSMutableDictionary *params;
@property (nonatomic, strong) NSMutableDictionary *files;
@property (nonatomic, strong) NSMutableDictionary *body;

@property (nonatomic, strong) NSMutableDictionary *cookies;
@property (nonatomic) NSTimeInterval timeOutSeconds;

+ (Request *)requestWithName:(NSString *)name;
+ (Request *)requestWithXmlNode:(DDXMLElement *)node;

- (void)addCookieValue:(NSString *)cookieValue forName:(NSString *)name;
- (void)addCookie:(NSHTTPCookie *)cookie forName:(NSString *)name;
- (void)setValue:(NSString *)value forParam:(NSString *)param;
- (void)setFile:(id)file forName:(NSString *)name;
- (Response *)response;

@end
